var cksh = {
    fillData:function () {
        $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'cd'}, function (cddata) {
            $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'jzfs'}, function (data) {
                ckshmxGrid($.webPath() + '/kcgl/cksh/cksh_xsmx?xsdId=' + $("[name='xsd.id']").val() || '', cddata, data);
            })
        });

//    $.post($.webPath() + '/organ/qyjg/qyjgmcList', function (jgdata) {
//        $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'fylb'}, function (data) {
//        })
//    })
    } }

$(function () {
    cksh.fillData();
    setTimeout(function () {
        $('#ckshForm').tabs('select', "销售明细");
    }, 100);
})

function ckshmxGrid(href, cdOptions, fsOptions) {
    var xsdId = $('#cksh_xsd_id').val();
    $("#cksh_mx").edatagrid({
        url:$.webPath() + "/kcgl/cksh/cksh_xsmx?xsdId=" + xsdId,
        fitColumns:false,
        singleSelect:true,
        fit:true,
//        width:1280,
//        height:275,
        checkbox:true,
        checkOnSelect:false,
        selectOnCheck:false,
        rownumbers:true,
        toolbar:"#cksh_xsdmx_toolbar",
        frozenColumns:[
            [
                {field:'wzgg.code', title:'物资编码',align: 'center', width:100, rowspan:2},
                {field:'wzgg.name', title:'物资名称',align: 'center', width:50, rowspan:2},
                {field:'wzgg.ggxh', title:'规格型号',align: 'center', width:50, rowspan:2},
                {field:'wzgg.dw', title:'单位', width:40,align: 'center', rowspan:2},
                {field:'cd.z', title:'产地', width:50,align: 'center', rowspan:2},
                {field:'jzfs.z', title:'记重方式', width:50,align: 'center', rowspan:2},
                {field:'kh.khbm', title:'卡号',align: 'center', width:100, rowspan:2}
            ]
        ],
        columns:[
            [
                {title:"开单", colspan:2},
                {title:"出库", colspan:2},
                {field:'bhsj',align: 'right', editor:{options:{min:0, groupSeparator:',', precision:4}}, title:'不含税价(元)', width:120, rowspan:2,
                    formatter:function (value) {
                        var val = formatJeForHtml(value);
                        return val;
                    }},
                {field:'bhse',align: 'right', editor:{options:{min:0, groupSeparator:',', precision:4}}, title:'不含税额(元)', width:120, rowspan:2,
                    formatter:function (value) {
                        var val = formatJeForHtml(value);
                        return val;
                    }},
                {field:'hsj', align: 'right',editor:{options:{min:0, groupSeparator:',', precision:4}}, title:'含税价(元)', width:120, rowspan:2,
                    formatter:function (value) {
                        var val = formatJeForHtml(value);
                        return val;
                    }}
            ] ,
            [
                {field:'js',align: 'right', editor:{ options:{min:0, groupSeparator:',', precision:0}}, title:'件数', width:70},
                {field:'sbsl',align: 'right', editor:{ options:{min:0, groupSeparator:',', precision:4}}, title:'重量', width:120,
                    formatter:function (value) {
                        var val = formatSlForHtml(value);
                        return val;
                    }},
                {field:'ck_js',align: 'right', editor:{type:'numberbox', options:{min:0, groupSeparator:',', precision:0}}, title:'件数', width:70},
                {field:'ck_sbsl',align: 'right', editor:{ type:'numberbox', options:{min:0, groupSeparator:',', precision:4}}, title:'重量', width:120,
                    formatter:function (value) {
                        var val = formatSlForHtml(value);
                        return val;
                    }}

            ]

        ],
        loadFilter:function (data) {
            $.each(data.rows, function () {
                this['ck_sbsl'] = this.sbsl;
                this['ck_js'] = this.js;
                this['bhse'] = this.ck_sbsl * this.bhsj;
            })
            return data;
        },
        onSelect:function (rowIndex, rowData) {
            //获取每个单元格
            $("#cksh_mx").edatagrid('editRow', rowIndex);
            var editors = $("#cksh_mx").datagrid('getEditors', rowIndex);
            if (editors.length == 0)
                return;
            var ckslEditor = editors[1];//税额编辑框
            ckslEditor.target.unbind("change").bind('change', function () {
                $(ckslEditor.target).numberbox('setValue', $(ckslEditor.target).val());
                rowData.bhse = formatMoney(rowData.bhsj * (parseFloat($(ckslEditor.target).numberbox('getValue'))));
                $("#cksh_mx").edatagrid('saveRow');
            });
        }
    })
}
